﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using HNQXYJ.Model;
using HNQXYJ.BLL;
using System.Web.SessionState;
namespace HNQXYJ.BLL
{
    /// <summary>
    /// UsersAsh 的摘要说明
    /// </summary>
    public class UsersAsh : IHttpHandler, IRequiresSessionState 
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string id = context.Request["id"];

            string action = context.Request["action"];
            //通过用户id删除用户
            if (id != "")
            {
               int Id= Convert.ToInt32(id);
               //int res = 0;
               //string procName = "UsersDeleteById";
               //SqlParameter[] paras = { 
               //                       new SqlParameter("@Id",SqlDbType.Int )
               //                       };
               //paras[0].Value = Id;
               //res = UsersBLL.ExecNoQuery(procName, paras);
               //if (res > 0)
               //{
               //    context.Response.Redirect("../DataCenterJS/UsersGetDataAll.aspx", true);
               //}
               string ranklevel = context.Session["ranklevel"].ToString();
               int length = ranklevel.Length;
                UsersBLL ub=new UsersBLL();
                bool flage = false;
                flage = ub.DeleteUserById(Id);
                if (flage)
                {
                    if (length == 1)
                    {
                        context.Response.Redirect("../HN_User/UserMgr.aspx", true);
                    }
                    if (length == 3)
                    {
                        context.Response.Redirect("../HN_User/UserMgrRankLevel.aspx", true);
                    }
                    if (length == 5)
                    {
                        context.Response.Redirect("../HN_User/UserMgrCounty.aspx", true);
                    }
                    
                }
            }

            //判断用户是否存在
            if (action == "IsUserName")
            {
                string username = context.Request["username"];
                Users user = new UsersBLL().GetUserByUserName(username);
                if (user != null)
                {
                    context.Response.Write("ok");
                }
                else
                {
                    context.Response.Write("no");
                }

            }
            //context.Response.Write("Hello World");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}